package com.example.demo.service;

import com.example.demo.entity.Inventory;
import com.example.demo.mapper.InventoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 库存MyBatis服务层
 */
@Service
public class InventoryMyBatisService {
    
    @Autowired
    private InventoryMapper inventoryMapper;
    
    /**
     * 查询库存不足的商品
     */
    public List<Inventory> findLowStockInventories(Integer threshold) {
        return inventoryMapper.findLowStockInventories(threshold);
    }
    
    /**
     * 根据仓库ID查询库存
     */
    public List<Inventory> findByWarehouseId(Long warehouseId) {
        return inventoryMapper.findByWarehouseId(warehouseId);
    }
    
    /**
     * 根据商品ID查询所有仓库的库存
     */
    public List<Inventory> findByProductId(Long productId) {
        return inventoryMapper.findByProductId(productId);
    }
    
    /**
     * 统计总库存价值
     */
    public Double getTotalInventoryValue() {
        return inventoryMapper.getTotalInventoryValue();
    }
    
    /**
     * 根据仓库统计库存价值
     */
    public Double getInventoryValueByWarehouse(Long warehouseId) {
        return inventoryMapper.getInventoryValueByWarehouse(warehouseId);
    }
    
    /**
     * 查询即将过期的库存
     */
    public List<Inventory> findExpiringSoon(Integer days) {
        return inventoryMapper.findExpiringSoon(days);
    }
    
    /**
     * 批量更新库存数量
     */
    public int updateStockBatch(List<Inventory> inventories) {
        return inventoryMapper.updateStockBatch(inventories);
    }
    
    /**
     * 查询库存变动记录
     */
    public List<Inventory> findStockMovements(Long productId, Long warehouseId) {
        return inventoryMapper.findStockMovements(productId, warehouseId);
    }
}
